/**
 * <p>Title: Spaceship</p>
 * <p>Description: The spaceship, do you get it?</p>
 * @author Guilherme Mauro Germoglio
 */

import java.awt.*;

public class Spaceship
    extends Body {

  //atributes
  private boolean wasHit;
  private boolean isThrust;
  private boolean isRearThrust;
  private boolean isTurnClockwise;
  private boolean isTurnCounterClockwise;
  final int R = 10;

  //methods
  /**
   * Spaceship's constructor.
   * @param x The X coordinate (the inicial coordinate)
   * @param y The Y coordinate (the inicial too...)
   */
  public Spaceship(int x, int y) {
    super(x, y, 0.0, 0.0, -90);
    this.wasHit = false;
    this.isRearThrust = false;
    this.isThrust = false;
    this.isTurnClockwise = false;
    this.isTurnCounterClockwise = false;
  }

  /**
   * Sets the condition that the spaceship was hit
   */
  public void hasBeenHit() {
    wasHit = true;
  }

  /**
   * Shows if the spaceship was hit or not
   * @return true if was hit, false case not
   */
  public boolean wasHit() {
    return wasHit;
  }

  /**
   * Shows if the spaceship is thrusting
   * @return true if so, false case not
   */

  public boolean isThrusting() {
    return isThrust;
  }

  /**
   * Shows if the spaceship is rear-thrusting
   * @return true if so, false case not
   */
  public boolean isRearThrusting() {
    return isRearThrust;
  }

  /**
   * Sets if the spaceship thrusts or not
   * @param thruster A boolean indicating yes or no...
   */
  public void setThruster(boolean thruster) {
    this.isThrust = thruster;
  }

  /**
   * Sets if the spaceship rear-thrusts or not
   * @param rearThruster A boolean indicating yes or no...
   */
  public void setRearThruster(boolean rearThruster) {
    this.isRearThrust = rearThruster;
  }

  /**
   * Shows if the spaceship is turning clockwise
   * @return true if so, false case not
   */
  public boolean isTurningClockwise() {
    return isTurnClockwise;
  }

  /**
   * Shows if the spaceship is turning counter clockwise
   * @return true if so, false case not
   */
  public boolean isTurningCounterClockwise() {
    return isTurnCounterClockwise;
  }

  /**
   * Sets if the spaceship is turning or not clockwise
   * @param turnClockwise A boolean indicating yes or no...
   */
  public void setTurnClockwise(boolean turnClockwise) {
    this.isTurnClockwise = turnClockwise;
  }

  /**
   * Sets if the spaceship is turning or not counter clockwise
   * @param turnCounterClockwise A boolean indicating yes or no...
   */
  public void setTurnCounterClockwise(boolean turnCounterClockwise) {
    this.isTurnCounterClockwise = turnCounterClockwise;
  }

  /**
   * Increases the spaceship's speed
   */
  public void increaseSpeed() {
    super.set_X_velocity(super.get_X_velocity() +
                         0.7 * Math.cos(super.getDirection() * Math.PI / 180));
    super.set_Y_velocity(super.get_Y_velocity() +
                         0.7 * Math.sin(super.getDirection() * Math.PI / 180));
  }

  /**
   * Decreases the spaceship's speed
   */
  public void decreaseSpeed() {
    super.set_X_velocity(super.get_X_velocity() -
                         0.7 * Math.cos(super.getDirection() * Math.PI / 180));
    super.set_Y_velocity(super.get_Y_velocity() -
                         0.7 * Math.sin(super.getDirection() * Math.PI / 180));
  }

  /**
   * Rotates the spaceship clockwise
   */
  public void rotateClockwise() {
    super.setDirection(getDirection() + (Math.PI) * 3);
  }

  /**
   * Rotates the spaceship counter clockwise
   */
  public void rotateCounterClockwise() {
    super.setDirection(getDirection() - (Math.PI) * 3);
  }

  /**
   * Draws and returns a polygon which is a spaceship
   * @param x The X coordinate
   * @param y The Y coordinate
   * @param r Something you could call the radius of the ship :)
   * @param direction The direction its front edge is pointing at
   * @return A polygon which is a spaceship
   *
   */
  public Polygon drawSpaceship(double x, double y, double r, double direction) {
    Polygon p = new Polygon();
    p.addPoint(
        (int) (x + r * Math.cos(direction * Math.PI / 180)),
        (int) (y + r * Math.sin(direction * Math.PI / 180))
        );

    p.addPoint(
        (int) (x + 0.5 * r * Math.cos( (direction + 135) * Math.PI / 180)),
        (int) (y + 0.5 * r * Math.sin( (direction + 135) * Math.PI / 180))
        );

    p.addPoint(
        (int) (x + 0.5 * r * Math.cos( (direction - 135) * Math.PI / 180)),
        (int) (y + 0.5 * r * Math.sin( (direction - 135) * Math.PI / 180))
        );
    return p;

  }

  /**
   * Draws and returns a polygon which is a spaceship
   * @return A polygon which is a spaceship
   */
  public Polygon drawSpaceship() {
    return drawSpaceship(super.getX(), super.getY(), R, super.getDirection());
  }
}